package com.lntea.springboot;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {
	
	@RequestMapping("/user")
	@ResponseBody
	String index(){
		return "user index";
	}
	
	@RequestMapping("/userInfo")
	@ResponseBody
	String userInfo(){
		return "zhangsan";
	}
	
	public static void main(String[] args) throws UnsupportedEncodingException {
		String binaryCode = "111001001011100010111010111001001011110110100000111001111001101010000100111001011010010110111101111001011010010110000111111001011011111110000011111001111000001010111001111010001011010110011110";
		
		// 正则表达式
		Pattern pattern = Pattern.compile("[10]{8}");
		// 定义匹配器
		Matcher matcher = pattern.matcher(binaryCode);
		
		List<Byte> list = new ArrayList();
		
		while(matcher.find()){
			list.add((byte)Integer.parseInt(matcher.group(), 2));
		}
		
		byte[] bytes = new byte[list.size()];
		int i = 0;
		for(Object b : list){
			bytes[i++] = (Byte)b;
		}
		
		System.out.println(new String(bytes, Charset.forName("utf-8")));
	}
}
